using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.Data;
using System.IO;
using System.Threading;
using System.Globalization;
namespace Test {
	class MqMsg300050 {
		static void MainX() {
			Thread.CurrentThread.CurrentCulture=new CultureInfo(1053,false);

			List<string> sqlServers=new List<string>();
			sqlServers.AddRange(Mixer.Combine("pon-wpsq21-db{0}\\in{0}","01,02,03,04,05,06,07,08,09,10,11,12"));
			//sqlServers.AddRange(Mixer.CombineEx("pon-wpsq{0:00}-db","1,3,6-10,12,13,16"));

			foreach(string server in sqlServers)
			{
				DAL dal=new DAL(server,"master");
				DataTable tab=dal.Query(@"create table #a1 (db varchar(255),tab varchar(255),crdate varchar(19))INSERT INTO #a1 (db,tab,crdate) exec sp_msforeachdb 'SELECT ''?'',name,convert(char(19),crdate,20) FROM [?]..sysobjects(nolock) where xtype=''U'' and name=''mqMessage''' SELECT * FROM #a1 where db not in('tempdb','msdb','model') ORDER BY 1 drop table #a1");


				foreach(DataRow row in tab.Rows)
				{
					Console.WriteLine(row["db"]);
					DAL mqDal=new DAL(server,row["db"].ToString());
					//DataTable mq=mqDal.Query("select id,inserted,payload from mqMessage(nolock) where Number='300050' and inserted>getdate()-150 order by id desc");
					//DataTable mq=mqDal.Query("select id,inserted,payload from mqMessage(nolock) where Number='300202' and inserted>getdate()-100 order by id desc");
					//DataTable mq=mqDal.Query("select Number,count(*)from mqMessage(nolock)where Number in('300042','300044','300045','300059') group by Number");
					DataTable mq=mqDal.Query("select Number,count(*)from mqMessage(nolock)where Number in('300041') group by Number");
				//DataTable mq=mqDal.Query("select id,inserted,payload from mqMessage(nolock) where Number='300303' and inserted>getdate()-2 order by id desc");
					if(mq.Rows.Count>0)
						Console.WriteLine(server+","+row[0]+","+row[1]);
					foreach(DataRow mqrow in mq.Rows)
						//Console.WriteLine(mqrow[0]+";"+mqrow[1]+";"+mqrow[2]);
					Console.WriteLine(mqrow[0]+";"+mqrow[1]+";");

				}


			}



			//string[] lines=File.ReadAllLines("MqSrv.txt");
			//foreach(string line in lines)
			//  if(!line.StartsWith("-"))
			//  {
			//    string[] arr=line.Split(',');
			//    DAL sql=new DAL(arr[0],arr[1]);
			//    //DataTable tab=sql.Query("select Number,count(*)[count] from mqMessage(nolock) group by Number");
			//    DataTable tab=sql.Query("select id,inserted,payload from mqMessage(nolock) where Number='300050' and inserted>getdate()-20 order by id desc");
			//    //DataTable tab=sql.Query("select top 10 * from mqMessage(nolock) where Number='300010' and inserted>getdate()-1 order by id desc");
			//    //DataTable tab=sql.Query("select * from mqMessage(nolock) where Number='300128' and inserted>getdate()-1 order by id desc");
			//    if(tab.Rows.Count>0)
			//      Console.WriteLine(arr[0]+","+arr[1]);
			//    foreach(DataRow row in tab.Rows)
			//      Console.WriteLine(row[0]+";"+row[1]+";"+row[2]);
			//  }
		}
		static void MainD() {
			Thread.CurrentThread.CurrentCulture=new CultureInfo(1053,false);
			DAL sql=new DAL("pon-wpsq16-db","directory");
			DataTable tab=sql.Query("select Number,count(*)[count] from mqMessage(nolock) group by Number");
			if(tab.Rows.Count>0)
				DAL.Csv(tab,"C:\\TestFile2.csv");
		}
	}
}
